<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@ taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Biblioteca Pessoal</title>
</head>
<body>
	<f:view>
		<h2>
			Biblioteca de <h:outputText value="#{usuarioMB.usuario.nome}"></h:outputText>
		</h2>		
		
		<h:form>
			<h:inputText value="#{livroMB.query}"></h:inputText>
			<h:commandButton value="Buscar livro por título ou nome de autor"
				action="#{livroMB.busca}" />
			<br /> <br />
			<h:commandButton value="Listar usuarios cadastrados"
				action="#{usuarioMB.listarOutrosUsuarios}" />
			<br/>	
			<h:commandLink value="Solicitações de Amizade" action="solicitacoes.jsp" ></h:commandLink>
			<br/>	
			<h:commandLink value="Amigos" action="amigos.jsp" ></h:commandLink>	
		</h:form>		
		 <br />
		<!-- Lista para serem aprovados - Emprestimos  -->
		<h:panelGroup rendered="#{livroMB.livrosEmprestados}">
			<h2>Atenção!! Livros emprestados a mais de um mês</h2>
			<h:dataTable border="1" value="#{livroMB.livrosEmprestados}" var="l">
				<h:column>
					<f:facet name="header">
						<h:outputText value="Nome do livro"></h:outputText>
					</f:facet>
					<h:outputText value="#{l[0].titulo}"></h:outputText>
				</h:column>
				<h:column>
					<f:facet name="header">
						<h:outputText value="ISBN"></h:outputText>
					</f:facet>
					<h:outputText value="#{l[0].isbn}"></h:outputText>
				</h:column>
				<h:column>
					<f:facet name="header">
						<h:outputText value="Ano de publicação"></h:outputText>
					</f:facet>
					<h:outputText value="#{l[0].anoPub}"></h:outputText>
				</h:column>
				<h:column>
					<f:facet name="header">
						<h:outputText value="Usuário"></h:outputText>
					</f:facet>
					<h:outputText value="#{l[0].usuario.nome}"></h:outputText>
				</h:column>
				<h:column>
					<f:facet name="header">
						<h:outputText value="Autores"></h:outputText>
					</f:facet>
					<h:outputText value="#{l[0].listaAutores}"></h:outputText>
				</h:column>
				<h:column>
					<f:facet name="header">
						<h:outputText value="Data de empréstimo"></h:outputText>
					</f:facet>
					<h:outputText value="#{l[1].time}">
						<f:convertDateTime pattern="dd/MM/yyyy" />
					</h:outputText>
				</h:column>
			</h:dataTable>
		</h:panelGroup>
		<h:panelGroup rendered="#{livroMB.temLivrosEmprestados}">
			<h2>Requisição de Emprestimos</h2>
			<h:dataTable border="1" value="#{loanMb.currentLoans}" var="l">
				<h:column>
					<f:facet name="header">
						<h:outputText value="Nome do livro"></h:outputText>
					</f:facet>
					<h:outputText value="#{l.book.titulo}"></h:outputText>
				</h:column>
				<h:column>
					<f:facet name="header">
						<h:outputText value="Requerente"></h:outputText>
					</f:facet>
					<h:outputText value="#{l.requester}"></h:outputText>
				</h:column>
				<h:column>
					<f:facet name="header">
						<h:outputText value="E-mail"></h:outputText>
					</f:facet>
					<h:outputText value="#{l.mail}"></h:outputText>
				</h:column>
				<h:column>
					<f:facet name="header">
						<h:outputText value="Fone"></h:outputText>
					</f:facet>
					<h:outputText value="#{l.fone}"></h:outputText>
				</h:column>
				<h:column>
					<f:facet name="header">
						Data do Pedido
					</f:facet>
					<h:outputText value="#{l.createdAt}">
						<f:convertDateTime pattern="dd/MM/yyyy" />
					</h:outputText>
				</h:column>
				<h:column>
					<f:facet name="header">
						Opcoes
					</f:facet>
					<h:form >
						<h:commandButton value="Aprovar" action="#{loanMb.saveLoanApproval(l)}"></h:commandButton>
					</h:form>
					<h:form>
						<h:commandButton value="Recusar" action="#{loanMb.saveLoanDeny(l)}"></h:commandButton>
					</h:form>
				</h:column>
			</h:dataTable>
		</h:panelGroup>
		<h:panelGroup rendered="#{livroMB.temLivrosEmprestados}">
			<h2>Requisição de Emprestimos</h2>
			<h:dataTable border="1" value="#{loanMb.currentLoans}" var="l">
				<h:column>
					<f:facet name="header">
						<h:outputText value="Nome do livro"></h:outputText>
					</f:facet>
					<h:outputText value="#{l.book.titulo}"></h:outputText>
				</h:column>
				<h:column>
					<f:facet name="header">
						<h:outputText value="Requerente"></h:outputText>
					</f:facet>
					<h:outputText value="#{l.requester}"></h:outputText>
				</h:column>
				<h:column>
					<f:facet name="header">
						<h:outputText value="E-mail"></h:outputText>
					</f:facet>
					<h:outputText value="#{l.mail}"></h:outputText>
				</h:column>
				<h:column>
					<f:facet name="header">
						<h:outputText value="Fone"></h:outputText>
					</f:facet>
					<h:outputText value="#{l.fone}"></h:outputText>
				</h:column>
				<h:column>
					<f:facet name="header">
						Data do Pedido
					</f:facet>
					<h:outputText value="#{l.createdAt}">
						<f:convertDateTime pattern="dd/MM/yyyy" />
					</h:outputText>
				</h:column>
				<h:column>
					<f:facet name="header">
						Opcoes
					</f:facet>
					<h:form >
						<h:commandButton value="Aprovar" action="#{loanMb.saveLoanApproval(l)}"></h:commandButton>
					</h:form>
					<h:form>
						<h:commandButton value="Recusar" action="#{loanMb.saveLoanDeny(l)}"></h:commandButton>
					</h:form>
				</h:column>
			</h:dataTable>
		</h:panelGroup>
		

		<a href="/BibliotecaPessoal/acervo.xhtml">Meu Acervo . com</a>
	</f:view>
</body>
</html>